package com.yydm.serviceorder.controller;

import com.yydm.commonutils.R;
//import com.yydm.serviceorder.entity.AutomobileOrder;
//import com.yydm.serviceorder.service.IAutomobileOrderLogService;
//import com.yydm.serviceorder.service.IAutomobileOrderService;
import com.yydm.serviceorder.service.IAutomobileOrderLogService;
import com.yydm.serviceorder.service.IAutomobileOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @Classname PayLogController
 * @Description TODO
 * @Version 1.0.0
 * @Date 2022/7/15 11:50
 * @Created by liu25
 */
@RestController
@RequestMapping("/aaaa")
//@CrossOrigin
public class PayLogController {

    @Autowired
    private IAutomobileOrderService automobileOrderService;

    @Autowired
    private IAutomobileOrderLogService automobileOrderLogService;

    @GetMapping("/createNative/{orderId}")
    public R createNative(@PathVariable String orderId) {
//        生成二维码
        Map map = automobileOrderService.createNative(orderId);
        System.out.println("二维码的集合" + map);
        return R.ok().data(map);
    }

    //    根据订单号查询状态
    @GetMapping("/queryStatus/{orderId}")
    public R queryStatus(@PathVariable String orderId) {

        Map<String, String> map = automobileOrderLogService.queryStatus(orderId);
        if (map == null) {
            return R.error().message("支付出错了");
        }
//        如果map不为空，获取里面的状态
        if (map.get("trade_status").equals("SUCCESS")) {
//            支付成功
            automobileOrderLogService.updateOrderStatus(map);
            return R.ok().message("支付成功了");
        }

        return R.ok().message("支付中");
    }


}
